﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StudentClass
{
    enum Specialty { Specialist, GreatSpecialist, TheGreatestSpecialist, NumberOne};
    enum University { Sofia, Plovdiv, Burgas };
    enum Faculty { IT, Psycho, Medical };

    class Student :ICloneable,IComparable
    {
        private string fullName;
        private string ssn;
        private string address;
        private string mobilePhone;
        private string email;
        private int course;
        private Specialty specialty;
        private University university;
        private Faculty faculty;

        string FullName
        {
            get { return this.fullName; }
            set { this.fullName = value; }
        }
        string SSN
        {
            get { return this.ssn; }
            set
            {
                if (value.Length != 10)
                {
                    throw new ArgumentException("SSN is not in the correct format!");
                }
                this.ssn = value;
            }
        }
        string Address
        {
            get { return this.address; }
            set { this.address = value; }
        }
        string MobilePhone
        {
            get { return this.mobilePhone; }
            set
            {
                if (!value.StartsWith("08"))
                {
                    throw new ArgumentException("Mobile phone is not in the correct format!");
                }
                this.mobilePhone = value;
            }
        }
        string Email
        {
            get { return this.email; }
            set
            {
                if (!value.Contains('@') || !(value.Contains('.')))
                {
                    throw new ArgumentException("This is not a correct e-mail!");
                }
                this.email = value;
            }
        }
        int Course
        {
            get
            { return this.course; }
            set
            {
                if (value < 1)
                {
                    throw new ArgumentException("Course must be at least 1!");
                }
                this.course = value;
            }
        }
        Specialty Specialty
        {
            get { return this.specialty; }
            set { this.specialty = value; }
        }
        University University
        {
            get { return this.university; }
            set { this.university = value; }
        }
        Faculty Faculty
        {
            get { return this.faculty; }
            set { this.faculty = value; }
        }

        public Student(string fullName, string ssn, string address, string mobilePhone, string email,
            int course, Specialty specialty, University university, Faculty faculty)
        {
            this.FullName = fullName;
            this.SSN = ssn;
            this.Address = address;
            this.MobilePhone = mobilePhone;
            this.Email = email;
            this.Course = course;
            this.Specialty = specialty;
            this.University = university;
            this.Faculty = faculty;
        }

        public override bool Equals(object obj)
        {
            Student student = obj as Student;
            if (student == null)
            {
                return false;
            }
            return Object.Equals(this.SSN, student.SSN);
        }

        public override int GetHashCode()
        {
            return this.SSN.GetHashCode();
        }

        public static bool operator ==(Student student1, Student student2)
        {
            return Student.Equals(student1, student2);
        }

        public static bool operator !=(Student student1, Student student2)
        {
            return !Student.Equals(student1, student2);
        }

        public override string ToString()
        {
            return string.Format(
                "Name: {0}\nSSN: {1}\nAddress: {2}\nMobile Phone: {3}\nE-mail: {4}\nCourse: {5}\nSpecialty: {6}\n" +
                "University: {7}\nFaculty: {8}", this.FullName, this.SSN, this.Address, this.MobilePhone,
                this.Email, this.Course, this.Specialty, this.University, this.Faculty);
        }


        object ICloneable.Clone()
        {
            return this.Clone();
        }

        public Student Clone()
        {
            Student studentCopy = new Student(this.FullName, 
                this.SSN, this.Address, this.MobilePhone, this.Email, 
                this.Course, this.Specialty, this.University, this.Faculty);
            return studentCopy;
        }

        public int CompareTo(Object obj)
        {
            Student student = obj as Student;
            if (student == null)
            {
                throw new ArgumentException("Cannot compare Object and Student");
            }
            int firstComparison = String.Compare(this.FullName, student.FullName);
            if (firstComparison == 0)
            {
                int secondComparison = String.Compare(this.SSN, student.SSN);
                return secondComparison;
            }
            return firstComparison;
        }
    }
}
